package codeTop;

/**
 * codeTop.q7
 *
 * @author 雨凡
 * @version codeTop.q7.java, v0.1
 * @date 2025/07/05/12:40
 */
public class q7 {
    public int reverse(int x) {
        int num1 = Integer.MAX_VALUE / 10;
        int mod1 = Integer.MAX_VALUE % 10;
        int num2 = Integer.MIN_VALUE / 10;
        int mod2 = Integer.MIN_VALUE % 10;
        int res = 0;
        if (x >= 0) {
            while (x != 0) {
                if (res > num1||(res==num1&&mod1<x)) {
                    return 0;
                }
                res = res * 10 + x % 10;
                x/=10;
            }
            return res;
        }else {
            while (x != 0) {
                if (res<num2||(res==num2&&mod2>x)) {
                    return 0;
                }
                res = res*10+x%10;
                x/=10;
            }
            return res;
        }
    }
}
